from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from .models import UserProfile

# # Register your models here.

# 将User Profile信息加入到Admin的User表中，内联
class ProfileInline(admin.StackedInline):
    model = UserProfile
    can_delete = False
    verbose_name_plural = '用户'


class MyUserAdmin(UserAdmin):
    # fieldsets = UserAdmin.fieldsets + (
    #     (None, {'fields': ('student_id','phone','true_name')}),
    # )
    # add_fieldsets = UserAdmin.add_fieldsets + (
    #     (None, {'fields': ('student_id','phone','true_name')}),
    # )s
    inlines = (ProfileInline,)
    # 'last_name','first_name'-姓氏，名字
    list_display = ['username','last_name','first_name','email','last_login']
    list_per_page = 10 #设置每页显示多少条记录，默认是100条
    list_display_links = ['username'] #设置哪些字段可以点击进入编辑界面
    search_fields = ['username','last_name','first_name'] #置哪些字段可以查询

# Re-register UserAdmin
admin.site.unregister(User) #去掉在admin中的注册
admin.site.register(User, MyUserAdmin) #用MyUserAdmin注册user

